package ModelLayer;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.*;
import java.util.ArrayList;

/**
 * The test class tester.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class TestProduct
{
    private Random randomGenerator = new Random();
    /**
     * Default constructor for test class tester
     */
    public TestProduct()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
    }

    /**
     * Test that adds 10,000 products in the system and the database.
     * After that every product is found by its name and deleted. 
     */
    @Test
    public void test_adding_thousand()
    {
        ModelLayer.Stock.initialize();
        ArrayList<String> customers = new ArrayList<>();
        for (int i = 0; i < 10000; i++)
        {
            assertEquals(true, ModelLayer.Stock.add_product(i+"", "Tools","Hardware", randomGenerator.nextDouble(), randomGenerator.nextDouble()*10, randomGenerator.nextInt(21), randomGenerator.nextInt(40)+50, randomGenerator.nextInt(40), randomGenerator.nextInt(20)+20,randomGenerator.nextInt(20)+20, "0", randomGenerator.nextDouble()));
        }
        
        for (int i = 0; i < 10000; i++)
       {
          assertEquals(true, ModelLayer.Stock.is_such_name(i+""));
          assertEquals(true, ModelLayer.Stock.delete_product(ModelLayer.Stock.get_art_nr_via_name(i+"")));
       }
        ModelLayer.Stock.save_data();
    }
}
